node.setMaterial function is very slow compared to GUI material assignation

Hi,

I made a script to automate material assignation to the various nodes within the scene tree.
I am parsing the SceneTree with a for loop searching for group node type only and assigning a material to leaf nodes only (the ones without a child).

the node.setMaterial function is taking ages to assign a material to a node (sometimes several minutes) whereas it is almost immediate when doing the equivalent action within GUI by drag and dropping a material on an component/node.

Here is a portion of the code used :

for node in root.find(name = ref, types = lux.NODE_TYPE_GROUP):
print("#### Processing current node : " + str(node))
if ( len(node.getChildren()) > 0 ) :
    print("No material assigned to " + str(node) + " : not a leaf ")
else :
    asnMat = "Test_Material"            #actually there is some logic here to determine the correct material
    print("#### before node.setMaterial(asnMat) , asnmat=" + str(asnMat))
    ti = current_milli_time() ;
    node.setMaterial(asnMat)
    deltati = current_milli_time() - ti
    assigntime += deltati 
    print("#### after node.setMaterial(asnMat) , asnmat=" + str(asnMat) + " in " + str(deltati) + " ms") 
    print("assigned " + asnMat + " to " + str(node) + "  -- idxM[" + mat+"] =" + str(idxM[mat]))

and here is a example of the execution logs for the above code

2024-06-04 14:21:09,287 arkrlog -- INFO     #### Processing csv row = ['279196-0.CATPRODUCT', 'Ca', '03 - ASSEMBLY', '', '']
2024-06-04 14:21:09,287 arkrlog -- DEBUG    #### Processing current node : <lux.SceneNode | name: "279196-0.CATProduct, Ca", kind: Group>
2024-06-04 14:21:09,288 arkrlog -- INFO     No material assigned to <lux.SceneNode | name: "279196-0.CATProduct, Ca", kind: Group> : not a leaf 
2024-06-04 14:21:09,288 arkrlog -- INFO     #### Processing csv row = ['235223-0_Z06.CATPRODUCT', 'Aa', '03 - ASSEMBLY', '', '']
2024-06-04 14:21:09,288 arkrlog -- DEBUG    #### Processing current node : <lux.SceneNode | name: "235223-0_Z06.CATProduct, Aa", kind: Group>
2024-06-04 14:21:09,288 arkrlog -- INFO     No material assigned to <lux.SceneNode | name: "235223-0_Z06.CATProduct, Aa", kind: Group> : not a leaf 
2024-06-04 14:21:09,288 arkrlog -- INFO     #### Processing csv row = ['020511-0_Z06.CATPART', 'Af', '01 - METAL', '', '']
2024-06-04 14:21:09,289 arkrlog -- DEBUG    #### Processing current node : <lux.SceneNode | name: "020511-0_z06.CATPart, Af", kind: Group>
2024-06-04 14:21:09,289 arkrlog -- DEBUG    #### before node.setMaterial(asnMat) , asnmat=AR_Metal Part-Steel
2024-06-04 14:21:41,548 arkrlog -- DEBUG    #### after node.setMaterial(asnMat) , asnmat=AR_Metal Part-Steel in 32258 ms
2024-06-04 14:21:41,549 arkrlog -- INFO     assigned AR_Metal Part-Steel to <lux.SceneNode | name: "020511-0_z06.CATPart, Af", kind: Group>  -- idxM[01 - METAL] =0
2024-06-04 14:21:41,549 arkrlog -- INFO     #### Processing csv row = ['235140-0_Z06.CATPART', 'Aa', '02 - PLASTIC', '', '']
2024-06-04 14:21:41,549 arkrlog -- DEBUG    #### Processing current node : <lux.SceneNode | name: "235140-0_Z06.CATPart, Aa", kind: Group>
2024-06-04 14:21:41,549 arkrlog -- DEBUG    #### before node.setMaterial(asnMat) , asnmat=AR_Black Plastic
2024-06-04 14:22:49,443 arkrlog -- DEBUG    #### after node.setMaterial(asnMat) , asnmat=AR_Black Plastic in 67895 ms
2024-06-04 14:22:49,443 arkrlog -- INFO     assigned AR_Black Plastic to <lux.SceneNode | name: "235140-0_Z06.CATPart, Aa", kind: Group>  -- idxM[02 - PLASTIC] =0
2024-06-04 14:22:49,444 arkrlog -- INFO     #### Processing csv row = ['246634-0_Z06.CATPART', 'Ab', '02 - PLASTIC', '', '']
2024-06-04 14:22:49,444 arkrlog -- DEBUG    #### Processing current node : <lux.SceneNode | name: "246634-0_Z06.CATPart, Ab", kind: Group>
2024-06-04 14:22:49,444 arkrlog -- DEBUG    #### before node.setMaterial(asnMat) , asnmat=AR_Light Gray Plastic
2024-06-04 14:24:25,747 arkrlog -- DEBUG    #### after node.setMaterial(asnMat) , asnmat=AR_Light Gray Plastic in 96303 ms
2024-06-04 14:24:25,747 arkrlog -- INFO     assigned AR_Light Gray Plastic to <lux.SceneNode | name: "246634-0_Z06.CATPart, Ab", kind: Group>  -- idxM[02 - PLASTIC] =1
2024-06-04 14:24:25,748 arkrlog -- INFO     assigned Materials for 279196-0-GRR_Ca.pvz (toonActive = False)
2024-06-04 14:24:25,748 arkrlog -- DEBUG    ######### Normal material assigned

As you can see it takes from 32 s to 96 s for each node assignation. I can’t figure out what I am doing wrong. Is there any other way to assign material to nodes having better performances ?

Thank you in advance for your help.